package models

import (
	"192.168.1.75/go-pkg/helper"
	"gorm.io/gorm"
)

// Role 角色
type Role struct {
	ID         string `json:"id,omitempty" gorm:"column:id;primaryKey;type:int;size:64;comment:主键id"`
	Name       string `json:"name,omitempty" gorm:"column:name;type:string;size:40;index:name_merchant,unique;comment:角色名称"`
	MerchantID string `json:"merchant_id,omitempty" gorm:"column:merchant_id;type:int;size:64;index:name_merchant,unique;comment:商户id"`
	CreatedAt  int64  `json:"created_at,omitempty" gorm:"autoCreateTime;column:created_at;type:int;size:64;comment:创建时间"`
	UpdatedAt  int64  `json:"updated_at,omitempty" gorm:"autoUpdateTime;column:updated_at;type:int;size:64;comment:更新时间"`
}

// TableName 表名称
func (r *Role) TableName() string {
	return "role"
}

// BeforeCreate 自增id
func (r *Role) BeforeCreate(tx *gorm.DB) (err error) {
	uuid, err := helper.UUID{}.String()
	if err != nil {
		return err
	}
	r.ID = uuid
	return nil
}

// 模式自动注册
func init() {
	Models = append(Models, &Role{})
}
